package com.dove.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.dove.utils.DateUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rabbit")
public class RabbitController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
	private RabbitTemplate rabbitTemplate;


	@GetMapping("/mq")
	public String mq(String out_trade_no) {
        logger.info("rabbit.successMqQueueExchange.successMqQueue" + DateUtil.format(new Date()));
		Map<String, String> map = new HashMap<String, String>();
		map.put("out_trade_no", out_trade_no);
		rabbitTemplate.convertAndSend("successMqQueueExchange","successMqQueue", JSON.toJSONString(map));
		return "success";
	}
}